<?php
/**
 * 公共操作类
 */
 namespace Admin\Controller;
 use Think\Controller;
 
class PublicController extends Controller {
	
	function uploadimg(){
        $upload = new \Think\Upload();// ;// 实例化上传类
        $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
//        $upload->autoSub =true ;
//        $upload->subType ='date' ;
//        $upload->dateFormat ='ymd' ;
        $upload->savePath =  './uploads/allimg/content/';// 设置附件上传目录
        if($upload->upload()){
            $info =  $upload->getUploadFileInfo();
            echo json_encode(array(
                    'url'=>$info[0]['savename'],
                    'title'=>htmlspecialchars($_POST['pictitle'], ENT_QUOTES),
                    'original'=>$info[0]['name'],
                    'state'=>'SUCCESS'
            ));
        }else{
            echo json_encode(array(
                    'state'=>$upload->getErrorMsg()
            ));
        }
	}
	
	function uploadify(){
		$ph=M('Attachment ');
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize  = 93145728 ;// 设置附件上传大小
        $upload->saveRule =rand(1,99999999);
        $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->savePath =  './uploads/allimg/photo/';// 设置附件上传目录
            if(!$upload->upload())
            {// 上传错误提示错误信息
                $this->error($upload->getErrorMsg());
            }else{// 上传成功 获取上传文件信息
                $info =  $upload->getUploadFileInfo();
            }
            for($i=0;$i<count($info);$i++)
            {
                $data['name']=$info[$i]['savename'];
                $data['size']=$info[$i]['size'];
                $data['type']=$info[$i]['extension'];
                
                
                $rs=$ph->add($data); 
                $data['id'] = $rs;
                echo json_encode($data);
            }
	}
	
	function clearcash(){//清楚缓存
		$dir = new \Org\Util\File;
		if(!$dir->empty_dir('./Runtime')){$dir->del_dir('./Runtime');}

		$data['status'] = 1;
		$this->ajaxReturn($data,'json');
		
	}
	function sendmail(){
		$this->display();
	}
	function dosendmail(){
		
	}
}
